<?php
require 'includes/master.inc.php';

// Kick out user if already logged in.
if ($Auth->loggedIn())
    redirect('index.php');

// Try to log in...
if (!empty($_POST['username'])) {
    $Auth->login($_POST['username'], $_POST['password']);
    if ($Auth->loggedIn())
        redirect('index.php');
    else
        $Error->add('username', "We're sorry, you have entered an incorrect username and password. Please try again.");
}

// Clean the submitted username before redisplaying it.
$username = isset($_POST['username']) ? htmlspecialchars($_POST['username']) : '';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>Data Site</title>
        <link rel="stylesheet" href="static/css/login-box.css" type="text/css" media="screen" title="Screen" charset="utf-8" />
        <style type="text/css">
            div.centered{
                display:block;
                /*set the div in the center of the screen*/
                position:absolute;
                top:20%;
                left:35%;
            }
        </style>
    </head>

    <body>
        <div class="centered">
        <div id="login-box">
            <form action="login.php" method="post">
                <H2>Login to Data Site</H2>
                <br />
                <br />
                <div id="login-box-name" style="margin-top:20px;">User name:</div><div id="login-box-field" style="margin-top:20px;"><input id="username" name="username" class="form-login" title="Username" value="<?php echo $username; ?>" size="30" maxlength="2048" /></div>
                <div id="login-box-name">Password:</div><div id="login-box-field"><input id="password" name="password" type="password" class="form-login" title="Password" value="" size="30" maxlength="2048" /></div>
                <br />
                <span class="login-box-options"><input type="checkbox" name="1" value="1"> Remember Me <a href="#" style="margin-left:30px;">Forgot password?</a></span>
                <br />
                <br />
                <p><input type="image" src="static/image/login-btn.png" name="btnlogin" value="Login" id="btnlogin" /></p>
            </form>
        </div>
            </div>
    </body>
</html>